package com.sskj.finance.ui.activity;


import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.ItemClickSupport;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.common.util.ClickUtil;
import com.sskj.finance.R;
import com.sskj.finance.R2;
import com.sskj.finance.bean.HomeBorrowTransTotal;
import com.sskj.finance.presenter.DYJKActivityPresenter;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;

@Route(path = RConfig.FINAN_DYJK)//抵押借款
public class DYJKActivity extends BaseActivity<DYJKActivityPresenter> {

    @BindView(R2.id.tvCardTitle)
    TextView tvCardTitle;
    @BindView(R2.id.tvUSDT)
    TextView tvUSDT;
    @BindView(R2.id.tvRMB)
    TextView tvRMB;
    @BindView(R2.id.lljk)
    LinearLayout lljk;
    @BindView(R2.id.lljb)
    LinearLayout lljb;
    @BindView(R2.id.llhz)
    LinearLayout llhz;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.finance_activity_dyjk;
    }

    @Override
    public DYJKActivityPresenter getPresenter() {
        return new DYJKActivityPresenter();
    }

    @Override
    protected void initView() {

        setTitle(App.INSTANCE.getString(R.string.finan_accountRecordActivity2_j));
        tvCardTitle.setText(App.INSTANCE.getString(R.string.finan_dYJKActivity2_j));
        setRightTitle(App.INSTANCE.getString(R.string.finan_mortgageRecordActivity1_j), v -> {
            ARouter.getInstance().build(RConfig.FINAN_MORTGAGE_RECORD).navigation();
        });
        ClickUtil.click(llhz, () -> {
            ARouter.getInstance().build(RConfig.FINAN_TRANSFER).navigation();
        });
        ClickUtil.click(lljb, () -> {
            ARouter.getInstance().build(RConfig.FINAN_BORROW).withBoolean(Constans.IS_BORROW_COIN, true).navigation();
        });
        ClickUtil.click(lljk, () -> {
            ARouter.getInstance().build(RConfig.FINAN_BORROW).withBoolean(Constans.IS_BORROW_COIN, false).navigation();
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        slimAdapter = SlimAdapter.create().register(R.layout.finan_recy_item_dyjk_main, new SlimInjector<HomeBorrowTransTotal>() {
            @Override
            public void onInject(HomeBorrowTransTotal data, IViewInjector injector, List payloads) {

                injector
                        .text(R.id.tvType, data.getMark())
                        .text(R.id.tvType1, data.getMark())
                        .text(R.id.tvLeftMoney, data.getOut() + data.getMark())
                        .text(R.id.tvRightMoney, data.getOut() + data.getMark());
            }
        }).attachTo(recyclerView).updateData(new ArrayList());

        ItemClickSupport.addTo(recyclerView)
                .setOnItemClickListener((recyclerView1, i, view) -> {
                    HomeBorrowTransTotal dataItem = (HomeBorrowTransTotal) slimAdapter.getDataItem(i);
                    ARouter.getInstance().build(RConfig.FINAN_MORTGAGE_RECORD).withString(Constans.PID, dataItem.getPid()).navigation();
                });

    }

    @Override
    protected void initData() {
        mPresenter.homeBorrowTransTotal();
    }

    public void updateUI(List<HomeBorrowTransTotal> data) {
        slimAdapter.updateData(data);
    }
}
